home *** CD-ROM | disk | FTP | other *** search
- /*********************************************/
- /* Generic substution form_alert() code & */
- /* form_center() code. */
- /* Written in Lattice C 5 */
- /* by Scott Sanders */
- /* (c)1991 Software Development Systems */
- /* Started 12/31/91, 02:39 AM */
- /* Version 1.0: Finished 1/01/92, 05:43 AM */
- /* Version 1.1: Finished 2/24/92, 02:19 AM */
- /*********************************************/
-
- /* Includes */
-
- #include <AES.H>
- #include <DOS.H>
- #include <VDI.H>
- #include <STRING.H>
- #include <STDIO.H>
- #include "ALERT.H"
-
- /* Resource for Alert */
-
- static short IMAG0[] = {
- 0x0003,0xc000,0x0006,0x6000,
- 0x000d,0xb000,0x001b,0xd800,
- 0x0037,0xec00,0x006f,0xf600,
- 0x00dc,0x3b00,0x01bc,0x3d80,
- 0x037c,0x3ec0,0x06fc,0x3f60,
- 0x0dfc,0x3fb0,0x1bfc,0x3fd8,
- 0x37fc,0x3fec,0x6ffc,0x3ff6,
- 0xdffc,0x3ffb,0xbffc,0x3ffd,
- 0xbffc,0x3ffd,0xdffc,0x3ffb,
- 0x6ffc,0x3ff6,0x37fc,0x3fec,
- 0x1bff,0xffd8,0x0dff,0xffb0,
- 0x06fc,0x3f60,0x037c,0x3ec0,
- 0x01bc,0x3d80,0x00dc,0x3b00,
- 0x006f,0xf600,0x0037,0xec00,
- 0x001b,0xd800,0x000d,0xb000,
- 0x0006,0x6000,0x0003,0xc000
- };
-
- static short IMAG1[] = {
- 0x3fff,0xfffc,0xc000,0x0003,
- 0x9fff,0xfff9,0xbfff,0xfffd,
- 0xdff8,0x3ffb,0x5fe0,0x0ffa,
- 0x6fc0,0x07f6,0x2f83,0x83f4,
- 0x3787,0xc3ec,0x1787,0xc3e8,
- 0x1bff,0x83d8,0x0bff,0x07d0,
- 0x0dfe,0x0fb0,0x05fc,0x1fa0,
- 0x06fc,0x3f60,0x02fc,0x3f40,
- 0x037c,0x3ec0,0x017c,0x3e80,
- 0x01bf,0xfd80,0x00bf,0xfd00,
- 0x00dc,0x3b00,0x005c,0x3a00,
- 0x006c,0x3600,0x002f,0xf400,
- 0x0037,0xec00,0x0017,0xe800,
- 0x001b,0xd800,0x000b,0xd000,
- 0x000d,0xb000,0x0005,0xa000,
- 0x0006,0x6000,0x0003,0xc000
- };
-
- static short IMAG2[] = {
- 0x007f,0xfe00,0x00c0,0x0300,
- 0x01bf,0xfd80,0x037f,0xfec0,
- 0x06ff,0xff60,0x0dff,0xffb0,
- 0x1bff,0xffd8,0x37ff,0xffec,
- 0x6fff,0xfff6,0xdfff,0xfffb,
- 0xb181,0x860d,0xa081,0x0205,
- 0xa4e7,0x3265,0xa7e7,0x3265,
- 0xa3e7,0x3265,0xb1e7,0x3205,
- 0xb8e7,0x320d,0xbce7,0x327d,
- 0xa4e7,0x327d,0xa0e7,0x027d,
- 0xb1e7,0x867d,0xbfff,0xfffd,
- 0xdfff,0xfffb,0x6fff,0xfff6,
- 0x37ff,0xffec,0x1bff,0xffd8,
- 0x0dff,0xffb0,0x06ff,0xff60,
- 0x037f,0xfec0,0x01bf,0xfd80,
- 0x00c0,0x0300,0x007f,0xfe00
- };
-
- static BITBLK rs_bitblk[] = {
- IMAG0,4,32,0,0,0x1,
- };
-
- static OBJECT rs_object[] = {
- -1,1,9,G_BOX,NORMAL,OUTLINED,(void *) 0x21100L,0x5,0x2,0x28,0x9,
- 2,-1,-1,G_IMAGE,NORMAL,NORMAL,(void *) 0L,0x2,0x1,0x4,0x2,
- 3,-1,-1,G_STRING,NORMAL,NORMAL,(void *) 0L,0x8,0x1,0x1e,0x1,
- 4,-1,-1,G_STRING,NORMAL,NORMAL,(void *) 1L,0x8,0x2,0x1e,0x1,
- 5,-1,-1,G_STRING,NORMAL,NORMAL,(void *) 2L,0x8,0x3,0x1e,0x1,
- 6,-1,-1,G_STRING,NORMAL,NORMAL,(void *) 3L,0x8,0x4,0x1e,0x1,
- 7,-1,-1,G_STRING,NORMAL,NORMAL,(void *) 4L,0x8,0x5,0x1e,0x1,
- 8,-1,-1,G_BUTTON,SELECTABLE|EXIT,NORMAL,(void *) 5L,0x1,0x7,0xc,0x1,
- 9,-1,-1,G_BUTTON,SELECTABLE|EXIT,NORMAL,(void *) 6L,0xe,0x7,0xc,0x1,
- 0,-1,-1,G_BUTTON,SELECTABLE|EXIT|LASTOB,NORMAL,(void *) 7L,0x1b,0x7,0xc,0x1
- };
-
- #define ANUM_OBS 10
-
- /* Module Variables */
-
- static short rsc_fix,cwidth,cheight,handle,planes,scrwid,scrhigh;
- static OBJECT *tree;
-
- /* Prototypes */
-
- int form_nalert();
- static void ObjcExtent(),init();
- void form_ncenter();
-
- int
- form_nalert(rect,def,work,image)
- GRECT *rect; /* Rectangle to center over: NULL = old way */
- short def; /* Default button: 0 = None */
- char *work; /* Standard GEM Alert String */
- short *image; /* Custom Image: 32x32 icon (64 shorts) or NULL */
- {
- char lines[5][31],buttons[3][11],*cp;
- short inc,type,num_lines=0,num_buttons=0,btmp,ltmp,tmp,j,ret,bwid=0,pixwid;
- GRECT area;
- long reserve,asize,rhigh,rlow,shigh,slow;
- char *holder;
- short pxyarray[8],hint;
- MFDB src,dest;
-
- if(!rsc_fix)
- init();
-
- ObSpec(ICON) = (BITBLK *) &rs_bitblk[0];
- ObSpec(LINE1) = lines[0];
- ObSpec(LINE2) = lines[1];
- ObSpec(LINE3) = lines[2];
- ObSpec(LINE4) = lines[3];
- ObSpec(LINE5) = lines[4];
- ObSpec(BUTTON1) = buttons[0];
- ObSpec(BUTTON2) = buttons[1];
- ObSpec(BUTTON3) = buttons[2];
-
- for(inc=0;inc<6;inc++) /* Clear Arrays */
- lines[inc][0] = 0;
- for(inc=0;inc<3;inc++)
- buttons[inc][0] = 0;
-
- cp = work; /* Parse alert string into arrays. */
- if(*cp++!='[')
- return NAFORMERR; /* Function returns 0 if error occurs */
- if(*cp<'0' || *cp>'4')
- return NAFORMERR;
- type = *cp++ - '0';
- if(*cp++!=']')
- return NAFORMERR;
- if(*cp++!='[')
- return NAFORMERR;
- while(*cp!='[') {
- inc = 0;
- while(*cp!='|' && *cp!=']') {
- lines[num_lines][inc] = *cp++;
- if(inc==30)
- return NAFORMERR;
- if(*cp==0)
- return NAFORMERR;
- inc++;
- }
- lines[num_lines][inc] = 0;
- *cp++;
- num_lines++;
- if(num_lines>5)
- num_lines = 5;
- }
- if(*cp++!='[')
- return NAFORMERR;
- while(*cp!=0) {
- inc = 0;
- while(*cp!='|' && *cp!=']') {
- buttons[num_buttons][inc] = *cp++;
- if(inc==10)
- return NAFORMERR;
- if(*cp==0)
- return NAFORMERR;
- inc++;
- }
- buttons[num_buttons][inc] = 0;
- num_buttons++;
- *cp++;
- if(num_buttons>3)
- num_buttons = 3;
- }
- /* Select an Icon */
- ShowObj(ICON);
- switch(type) {
- case 0:
- BiData(0) = IMAG0; /* Still Needs to Point Somewhere */
- HideObj(ICON);
- break;
- case 1:
- BiData(0) = IMAG0;
- break;
- case 2:
- BiData(0) = IMAG1;
- break;
- case 3:
- BiData(0) = IMAG2;
- break;
- case 4:
- BiData(0) = image;
- break;
- }
-
- for(inc=LINE1;inc<=LINE5;inc++) { /* Adjust Alert Lines */
- if(type==0)
- ObX(inc) = cwidth*2;
- else
- ObX(inc) = cwidth*4+32;
- if(num_lines>inc-LINE1) {
- ObW(inc) = (int)(strlen(lines[inc-LINE1])*cwidth);
- ShowObj(inc);
- }
- else
- HideObj(inc);
- }
-
- for(inc=BUTTON1;inc<=BUTTON3;inc++) { /* Adjust Buttons */
- if(num_buttons>inc-BUTTON1) {
- j = (int)((strlen(buttons[inc-BUTTON1])+1)*cwidth);
- if(j>bwid)
- bwid = j;
- ShowObj(inc);
- }
- else
- HideObj(inc);
- }
- for(inc=BUTTON1;inc<BUTTON1+num_buttons;inc++) {
- ObW(inc) = bwid+cwidth*1;
- if(inc>BUTTON1)
- ObX(inc) = ObX(inc-1)+ObW(inc-1)+(cwidth*2);
- else
- ObX(inc) = cwidth*2;
- }
-
- /* Find out minimum alert width */
-
- btmp = (cwidth*2)+ObX(num_buttons-1+BUTTON1)+ObW(num_buttons-1+BUTTON1);
- ltmp = 0;
- for(inc=LINE1;inc<LINE1+num_lines;inc++) {
- if(ObW(inc)>ltmp)
- ltmp = ObW(inc);
- }
- ltmp += (cwidth*4)+(type==0 ? 0 : 32+(cwidth*2));
- if(ltmp>btmp) {
- tmp = (ltmp-(ObX(num_buttons-1+BUTTON1)+ObW(num_buttons-1+BUTTON1)-ObX(BUTTON1)))/2;
- j = tmp-ObX(BUTTON1);
- for(inc=BUTTON1;inc<BUTTON1+num_buttons;inc++)
- ObX(inc) += j;
- ObW(ROOT) = ltmp;
- }
- else
- ObW(ROOT) = btmp;
-
- /* Find out minimum alert height */
- ltmp = cheight*(num_lines+4);
- btmp = (cheight*4)+32;
- ObH(ROOT) = max(ltmp,btmp);
- for(inc=BUTTON1;inc<=BUTTON3;inc++) {
- ObY(inc) = ObH(ROOT)-cheight*2;
- if(inc-BUTTON1+1 == def)
- MakeDefault(inc);
- else
- NoDefault(inc);
- }
-
- /* Center Object */
- if(rect==NULL) {
- area.g_x = 0;
- area.g_y = 0;
- area.g_w = scrwid;
- area.g_h = scrhigh;
- }
- else {
- area.g_x = rect->g_x;
- area.g_y = rect->g_y;
- area.g_w = rect->g_w;
- area.g_h = rect->g_h;
- }
- form_ncenter(tree,&area);
-
- /* Enable Clipping */
- pxyarray[0] = 0;
- pxyarray[1] = 0;
- pxyarray[2] = scrwid;
- pxyarray[3] = scrhigh;
- vs_clip(handle,1,pxyarray);
-
- pixwid = area.g_w;
- if(pixwid%16 != 0)
- pixwid +=16-(pixwid%16);
- hint = (pixwid/16*planes);
-
- reserve = (long)(hint*2*area.g_h);
-
- wind_get(DESK,WF_SCREEN,(short *)&rhigh,(short *)&rlow,(short *)&shigh,(short *)&slow);
- holder = (char *)(rhigh | ((rlow>>16)&0xFFFF));
- asize = (shigh | ((slow>>16)&0xFFFF));
-
- if(reserve>asize) {
- vs_clip(handle,0,NULL);
- return NAMEMERR;
- }
-
- pxyarray[0] = area.g_x;
- pxyarray[1] = area.g_y;
- pxyarray[2] = area.g_x+area.g_w;
- pxyarray[3] = area.g_y+area.g_h;
- pxyarray[4] = 0;
- pxyarray[5] = 0;
- pxyarray[6] = area.g_w;
- pxyarray[7] = area.g_h;
- src.fd_addr = NULL;
- dest.fd_addr = holder;
- dest.fd_w = pixwid;
- dest.fd_h = (short)(reserve/(pixwid/8));
- dest.fd_wdwidth = pixwid/16;
- dest.fd_stand = 0;
- dest.fd_nplanes = planes;
-
- graf_mouse(M_OFF,NULL);
- vro_cpyfm(handle,S_ONLY,pxyarray,&src,&dest);
- graf_mouse(M_ON,NULL);
-
- objc_draw(tree,ROOT,MAX_DEPTH,ELTS(area));
- ret = form_do(tree,0);
- Deselect(ret);
-
- dest.fd_addr = NULL;
- src.fd_addr = holder;
- src.fd_w = pixwid;
- src.fd_h = (short)(reserve/(pixwid/8));
- src.fd_wdwidth = pixwid/16;
- src.fd_stand = 0;
- src.fd_nplanes = planes;
- pxyarray[0] = 0;
- pxyarray[1] = 0;
- pxyarray[2] = area.g_w;
- pxyarray[3] = area.g_h;
- pxyarray[4] = area.g_x;
- pxyarray[5] = area.g_y;
- pxyarray[6] = area.g_x+area.g_w;
- pxyarray[7] = area.g_y+area.g_h;
-
- graf_mouse(M_OFF,NULL);
- vro_cpyfm(handle,S_ONLY,pxyarray,&src,&dest);
- graf_mouse(M_ON,NULL);
-
- vs_clip(handle,0,NULL);
- }
-
- void
- form_ncenter(tree,base)
- OBJECT *tree;
- GRECT *base;
- {
- if(!rsc_fix)
- init();
-
- if(ObW(ROOT) > base->g_w)
- ObX(ROOT) = base->g_x-((ObW(ROOT)-base->g_w)/2);
- else
- ObX(ROOT) = base->g_x+((base->g_w-ObW(ROOT))/2);
- if(ObH(ROOT) > base->g_h)
- ObY(ROOT) = base->g_y-((ObH(ROOT)-base->g_h)/2);
- else
- ObY(ROOT) = base->g_y+((base->g_h-ObH(ROOT))/2);
-
- if(ObX(ROOT)<5) /* Allow for Outline */
- ObX(ROOT) = 5;
- if(ObY(ROOT)<24) /* Allow for Menu Bar */
- ObY(ROOT) = 24;
- if(ObX(ROOT)+ObW(ROOT)+5 > scrwid)
- ObX(ROOT) = scrwid-ObW(ROOT);
- if(ObY(ROOT)+ObH(ROOT)+5 > scrhigh)
- ObY(ROOT) = scrhigh-ObH(ROOT);
-
- ObjcExtent(tree,base);
- }
-
- /* Code below modified from Atari's Ken B's AESUTIL.C */
-
- static void
- ObjcExtent( tree, r )
- OBJECT *tree;
- GRECT *r;
- {
- short offset, border;
- void *pspec;
-
- objc_offset( tree, ROOT, &r->g_x, &r->g_y );
- *(long *)&r->g_w = *(long *)&ObW(ROOT);
-
- pspec = (void *)&ObSpec(ROOT);
- border = ((ObInfo *)pspec)->border;
- if(border>=0)
- offset = 0;
- else
- offset = border, border = -border;
-
-
- if( IsOutlined(ROOT) && offset > -3 )
- offset = -3;
-
- if( offset ) {
- r->g_x += offset;
- r->g_w -= offset*2;
- r->g_y += offset;
- r->g_h -= offset*2;
- }
-
- if( IsShadowed(ROOT) && border )
- r->g_w += 2 * border, r->g_h += 2 * border;
- }
-
- void
- init()
- {
- int dum,work_out[57];
-
- handle = graf_handle(&cwidth,&cheight,&dum,&dum);
- vq_extnd(handle,0,work_out);
- scrwid = work_out[0];
- scrhigh = work_out[1];
- vq_extnd(handle,1,work_out);
- planes = work_out[4];
-
- tree = (OBJECT *)&rs_object[0];
- for(dum=0;dum<ANUM_OBS;dum++)
- rsrc_obfix(tree,dum);
-
- rsc_fix = TRUE;
- }